"""make user_target not nullable

Revision ID: 67c38b3f39c2
Revises: a5466912fad0
Create Date: 2023-03-20 11:08:42.883556

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects.postgresql import JSONB

# revision identifiers, used by Alembic.
revision = "67c38b3f39c2"
down_revision = "a5466912fad0"
branch_labels = None
depends_on = None


def jsonb_if_postgresql_else_json():
    return sa.JSON().with_variant(JSONB, "postgresql")


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("nonebot_bison_user", schema=None) as batch_op:
        batch_op.alter_column(
            "user_target",
            existing_type=jsonb_if_postgresql_else_json(),
            nullable=False,
        )

    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("nonebot_bison_user", schema=None) as batch_op:
        batch_op.alter_column(
            "user_target",
            existing_type=jsonb_if_postgresql_else_json(),
            nullable=True,
        )

    # ### end Alembic commands ###
